package com.forest.oss.impl.tencent;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import com.forest.oss.constants.OssEnum;
import com.forest.oss.impl.OssProperties;

import javax.annotation.PostConstruct;

@Slf4j
@Data
@Configuration
@EnableConfigurationProperties
@EqualsAndHashCode(callSuper = true)
@ConfigurationProperties("config.oss.tencent")
@ConditionalOnProperty(prefix = "config.oss.tencent", name = "enable", havingValue = "true")
public class TencentOssProperties extends OssProperties {

    @Override
    public String getAppKeyId() {
        return StrUtil.isNotBlank(appKeyId) ? appKeyId : "";
    }

    @Override
    public String getAppSecret() {
        return StrUtil.isNotBlank(appSecret) ? appSecret : "";
    }

    @Override
    public OssEnum getType() {
        return ObjectUtil.isNull(type) ? type : OssEnum.TENCENT;
    }

    @Override
    public String getEnable() {
        return StrUtil.isNotBlank(enable) ? enable : "false";
    }

    @Override
    public String getBucketDomain() {
        return StrUtil.isNotBlank(bucketDomain) ? bucketDomain : "";
    }

    @Override
    public String getEndPoint() {
        return StrUtil.isNotBlank(endPoint) ? endPoint : "";
    }

    @Override
    public String getBucket() {
        return StrUtil.isNotBlank(bucket) ? bucket : "/";
    }

    @Override
    public String getProject() {
        return StrUtil.isNotBlank(project) ? project : "";
    }

    @PostConstruct
    public void init() {
        log.info("初始化OSS参数：bucket = {}", getBucket());
    }
}
